#include "warnRecodeTabModel.h"

warnRecodeTabModel::warnRecodeTabModel(QObject *)
{

}
int warnRecodeTabModel::rowCount(const QModelIndex &) const
{
    return dataList.size();
}

int warnRecodeTabModel::columnCount(const QModelIndex &) const
{
    return 6;
}

QVariant warnRecodeTabModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (role == Qt::DisplayRole) {
        const auto &data = dataList[index.row()];
        switch (index.column()) {
        case 0: return data.id;
        case 1: return data.device_id;
        case 2: return data.timestamp;
        case 3: return data.content;
        case 4: return data.status;
        case 5: return data.note;
        default: return QVariant();
        }
    }else if (role == Qt::TextAlignmentRole) {
        return Qt::AlignCenter;
    }
    return QVariant();
}

QVariant warnRecodeTabModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
        switch (section) {
        case 0: return "记录id";
        case 1: return "设备id";
        case 2: return "时间";
        case 3: return "警告内容";
        case 4: return "状态";
        case 5: return "备注";
        default: return QVariant();
        }
    }
    return QVariant();
}

void warnRecodeTabModel::updateAllDeviceList(const QList<wareRecodeModel > &newList)
{
    beginResetModel();
    dataList = newList;
    endResetModel();
}
